package com.usefullc.blog.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.blog.domain.ArticleSync;
import com.usefullc.blog.mapper.ArticleSyncMapper;
import com.usefullc.blog.query.ArticleSyncQuery;
import com.usefullc.blog.vo.ArticleSyncVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 文章同步服务类
 * @author: 星空
 * @date: 2022-07-12
 */
@Service
public class ArticleSyncService extends AbstractBizService<ArticleSyncMapper, ArticleSync, ArticleSyncQuery> {


    @Override
    protected QueryWrapper<ArticleSync> getQueryWrapper(ArticleSyncQuery query) {
        QueryWrapper<ArticleSync> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<ArticleSyncVo> findVoByPage(ArticleSyncQuery query){
        Pager<ArticleSync> page = this.findByPage(query);
        Pager<ArticleSyncVo> newPage = new Pager<>(page);
        List<ArticleSync> dataList = page.getDataList();
        List<ArticleSyncVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (ArticleSync articleSync : dataList) {
            ArticleSyncVo articleSyncVo = BeanUtils.beanCopy(articleSync, ArticleSyncVo.class);
            newDataList.add(articleSyncVo);
        }
        return newPage;
    }


}
